import { Node, arr2nTree } from "@/基本数据结构/n叉树";
export function preorder2(root: Node | null): number[] {
  if (!root) return [];
  const arr: number[] = [];
  const fn = (node: Node | null) => {
    if (!node) return;
    arr.push(node.val);
    node.children.forEach((child) => {
      fn(child);
    });
  };
  fn(root);
  return arr;
}

export function preorder(root: Node | null): number[] {
  if (!root) return [];
  const arr: number[] = [root.val];
  for (let index = 0; index < root.children.length; index++) {
    const node = root.children[index];
    const temp = preorder(node);
    arr.push(...temp);
  }
  return arr;
}
